package com.tr.rentcar.controller.userc;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.tr.rentcar.model.bean.User;
import com.tr.rentcar.model.dao.OrderDao;

/**
 * Servlet implementation class UserOrdersCaController
 */
@WebServlet("/user/orderca")
public class UserOrdersCaController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	OrderDao od=new OrderDao();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String ostatus=request.getParameter("ostatus");
		String Current=request.getParameter("Current");
		User user=(User) request.getSession().getAttribute("userinfo");
		int c=(Integer.parseInt(Current)-1)*9;
		PrintWriter out=response.getWriter();
		try {
			if (ostatus.equals("全部")) {
				out.println(JSONArray.toJSONString(od.getById(user.getUid(), c)));
				return;
			}
			out.println(JSONArray.toJSONString(od.getByIdState(user.getUid(), ostatus, c)));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
